<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:msbld="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:nyext="urn:noury-extensions" exclude-result-prefixes="xsl nyext msxsl msbld">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />

  <xsl:param name="solution" />
  <xsl:param name="trmdir" />

  <xsl:include href="functions.xslt" />

  <xsl:template name="generate-user-file">
    <Project DefaultTargets="Rebuild">

      <xsl:comment> Import external targets </xsl:comment>
      <Import Project="$(MSBuildProjectDirectory)\misc\NourY.CSharp.targets" />

      <PropertyGroup>
        <xsl:comment>Version</xsl:comment>
        <VersionMajor>1</VersionMajor>
        <VersionMinor>0</VersionMinor>
        <VersionBuild>0</VersionBuild>
        <VersionRevision>0</VersionRevision>
    
        <BuildDependsOn>UpdateVersion</BuildDependsOn>
      </PropertyGroup>


      <xsl:comment> Platforms </xsl:comment>
      <ItemDefinitionGroup>
        <Platforms>
          <Tested>false</Tested>
          <Analyzed>false</Analyzed>
          <Released>true</Released>
        </Platforms>
      </ItemDefinitionGroup>
      <ItemGroup>
        <xsl:for-each select="/manifest/configuration/platform">
          <xsl:variable name="pfcode">
            <xsl:choose>
              <xsl:when test="@name='.NET 2.0'">
                <xsl:text>$(NET_2_0_Platform)</xsl:text>
              </xsl:when>
              <xsl:when test="@name='.NET 3.0'">
                <xsl:text>$(NET_3_0_Platform)</xsl:text>
              </xsl:when>
              <xsl:when test="@name='.NET CF 2.0 (Pocket PC 2003)'">
                <xsl:text>$(NET_CF_2_0_PocketPC_Platform)</xsl:text>
              </xsl:when>
              <xsl:when test="@name='.NET CF 2.0 (Windows CE 5.0)'">
                <xsl:text>$(NET_CF_2_0_WinCE_Platform)</xsl:text>
              </xsl:when>
              <xsl:when test="@name='.NET CF 2.0 (Windows Mobile 5.0 Pocket PC)'">
                <xsl:text>$(NET_CF_2_0_WinMob50PocketPC_Platform)</xsl:text>
              </xsl:when>
              <xsl:when test="@name='.NET CF 2.0 (Windows Mobile 5.0 Smartphone)'">
                <xsl:text>$(NET_CF_2_0_WinMob50Smartphone_Platform)</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>$(NET_2_0_Platform)</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <Platforms>
            <xsl:attribute name="Include">
              <xsl:value-of select="$pfcode" />
            </xsl:attribute>
          </Platforms>
        </xsl:for-each>
      </ItemGroup>

      <xsl:comment> Projects </xsl:comment>
      <ItemGroup>
        <Projects>
          <xsl:attribute name="Include">
            <xsl:value-of select="$solution" />
          </xsl:attribute>
          <Released>true</Released>
        </Projects>
      </ItemGroup>

      <!--<ItemGroup>
        <Tests Include="NUnit">
          <Project>Libraries.NUnit.sln</Project>
          <Container>Salamanca.NUnit.dll</Container>
          <Metadata>Libraries.NUnit.vsmdi</Metadata>
        </Tests>
      </ItemGroup>-->

      <!--<ItemGroup>
        <Analysis Include="Libraries">
          <Project>Libraries.sln</Project>
          <Report>Libraries.FxCop</Report>
        </Analysis>
      </ItemGroup>-->


      <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
    
      <xsl:comment> Version number </xsl:comment>
      <Target Name="UpdateVersion">
        <Version VersionFile="Version.txt" RevisionType="Automatic" BuildType="Automatic">
          <Output TaskParameter="Build" PropertyName="AutoVersionBuild" />
          <Output TaskParameter="Revision" PropertyName="AutoVersionRevision" />
        </Version>
    
        <FileUpdate
          Files="Version.cs.tpl"
          Regex="(?&lt;=AssemblyVersion\W{2})[\d\.]+(?=\W{2})"
          ReplacementText="$(VersionMajor).$(VersionMinor).$(AutoVersionBuild).$(AutoVersionRevision)"
          />
        <FileUpdate
          Files="Version.cs.tpl"
          Regex="(?&lt;=AssemblyInformationalVersion\W{2})[\d\.]+(?=\W{2})"
          ReplacementText="$(VersionMajor).$(VersionMinor).$(VersionBuild).$(VersionRevision)"
          />
        <FileUpdate
          Files="Version.cs.tpl"
          Regex="(?&lt;=AssemblyFileVersion\W{2})[\d\.]+$WCREV$(?=\W{2})"
          ReplacementText="$(VersionMajor).$(VersionMinor).$(VersionBuild).$WCREV$"
          />
        <Exec
          Command="&quot;$(SVN_HOME)\SubWCRev.exe&quot; ..\src Version.cs.tpl Version.cs"
          WorkingDirectory="$(MSBuildProjectDirectory)"
        />
      </Target>

      <xsl:comment> Import external targets </xsl:comment>
      <Import Project="$(MSBuildProjectDirectory)\misc\Salamanca.Project.msbuild" />
    </Project>
  </xsl:template>

  <!-- Entry point for the transformation -->
  <xsl:template match="/">
    <xsl:call-template name="generate-user-file" />
  </xsl:template>
</xsl:stylesheet>
